import E from 'wangeditor'
export default {
  data() {
    return {
      editor : null
    }
  },
  getEditor() {
    this.editor = new E('#editor');
    this.editor.create();
  },
  getEditorForLearnPage() {
    this.editor = new E('#editor');
    // 配置菜单栏，删减菜单，调整顺序
    this.editor.config.height = 300
    this.editor.config.menus = [
      'head',
      'bold',
      'italic',
      'strikeThrough',
      'indent',
      'list',
      'justify',
      'quote',
      'image',
      'table',
      'code',
      'splitLine',
      'undo',
    ]
    this.editor.create();
  },
  setText(content) {
    this.editor.txt.txt(content);
  },
  getText() {
    return this.editor.txt.txt();
  },
  setHtml(content) {
    this.editor.txt.html(content);
  },
  getHtml() {
    return this.editor.txt.html();
  },
  htmlToTxt(html) {
    return html.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' ')
  },
  readOnly() {
    this.editor.disable();
  }
}
